package com.flying.acls.domain.context;

import com.flying.acls.model.ResType;
import lombok.Data;

import java.util.HashMap;

/**
 * If multi vos, be careful of the vo sequence.
 */
@Data
public class ExpressionContext {
    private Object accessingObject;
    private Object principal;
    private Object requiredPermission;

    private ResType resType;
    private HashMap<String, String> env;

    public ExpressionContext(Object accessingObject, Object principal, Object permission, ResType resType) {
        this(accessingObject, principal, permission, resType, new HashMap<String, String>());
    }

    public ExpressionContext(Object accessingObject, Object principal, Object permission, ResType resType, HashMap<String, String> env) {
        this.accessingObject = accessingObject;
        this.principal = principal;
        this.requiredPermission = permission;
        this.resType = resType;
        this.env = env;
    }

    public synchronized void addEnvVar(String key, String value) {
        if (!env.containsKey(key)) env.put(key, value);
    }

    public String getEnvVar(String key) {
        if (env == null) return null;
        return env.get(key);
    }
}